package com.wdf.project03.controller;

import com.wdf.project03.Mapper.UserMapper;
import com.wdf.project03.pojo.Result;
import com.wdf.project03.pojo.User;
import com.wdf.project03.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("listUser")
    private Result list(){
        List<User> listUser = userService.list();
        return Result.success(listUser);
    }
    @GetMapping("/getById/{id}")
    private Result getById(@PathVariable int id){
        User user = userService.getById(id);
        return Result.success(user);
    }
    @PostMapping("/insertUser")
    private Result insertUser(@RequestBody User user){
        userService.insert(user);
        return Result.success(user);
    }
    @DeleteMapping ("/deleteById/{id}")
    private Result deleteById(@PathVariable int id){
        userService.deleteById(id);
        return Result.success();
    }
}
